package com.dc.dao;

import com.dc.dao.vo.ShipNameAndRepairIdVO;
import com.dc.entity.ShipRepairEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

public interface ShipRepairDao extends JpaRepository<ShipRepairEntity, Long>, JpaSpecificationExecutor<ShipRepairEntity> {


    public Page<ShipRepairEntity> findByEnterTimeBetweenAndShipId(Date enterTimeBegin, Date enterTimeEnd, Long shipId, Pageable pageable);

    public Page<ShipRepairEntity> findByEnterTimeIsAfterAndShipId(Date enterTimeBeginBegin, Long shipId, Pageable pageable);

    public Page<ShipRepairEntity> findByEnterTimeIsBeforeAndShipId(Date enterTimeBeginEnd, Long shipId, Pageable pageable);

    public boolean existsByShipId(Long shipId);

    public List<ShipRepairEntity> findByOutTimeBetweenAndComplete(Date outTimeBegin, Date outTimeEnd, Integer complete);

    public List<ShipRepairEntity> findByComplete(Integer complete);

    @Query(nativeQuery = true, value = "select tsr.id as shipRepairId, ts.name as shipName from t_ship ts join t_ship_repair tsr on ts.id = tsr.ship_id")
    public List<ShipNameAndRepairIdVO> findShipNameAndRepairIdList();




}
